import pandas as pd


def generate_3h_kline():
    """
    用1h的K线合成3h的k线
    :return:
    """
    df_1h = pd.read_csv('BTC_kline_1h_merge.csv', parse_dates=['datetime'], index_col='datetime')
    df_3h = df_1h.resample('3H').agg({
        'open': 'first',
        'high': 'max',
        'low': 'min',
        'close': 'last',
    }).dropna()
    df_3h = df_3h.reset_index(drop=False)
    df_3h.to_csv('BTC_kline_3h_merge.csv', index=False)


if __name__ == '__main__':
    generate_3h_kline()